package com.example.word_book.service;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.word_book.R;
import com.example.word_book.bean.Word;
import com.example.word_book.utils.SqlHelp;

import java.util.ArrayList;

public class BrowseWordActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_browse_word);
        init();
    }

    private void init() {
        Intent intent = getIntent();
        ImageView img_back = findViewById(R.id.img_back);

        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        TextView tv_wordName = findViewById(R.id.tv_wordName);
        tv_wordName.setText(intent.getStringExtra("word"));

        TextView tv_word = findViewById(R.id.tv_word);
        tv_word.setText(intent.getStringExtra("word"));

        SqlHelp sqlHelp = new SqlHelp(this);
        Word word = sqlHelp.selectWord(intent.getStringExtra("word"));

        ListView lv = findViewById(R.id.lv_translation);
        lv.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return word.getType().length;
            }

            @Override
            public Object getItem(int i) {
                return word.getType()[i];
            }

            @Override
            public long getItemId(int i) {
                return i;
            }

            @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                view = View.inflate(BrowseWordActivity.this, R.layout.list_item_translation, null);
                TextView tv_type = view.findViewById(R.id.tv_type);
                TextView tv_translation = view.findViewById(R.id.tv_translation);
                tv_type.setText(word.getType()[i]);
                tv_translation.setText(String.valueOf(word.getTranslation()[i]));
                return view;
            }
        });

    }
}